package com.bensonbasement.snorflux.server.world;

import java.io.Serializable;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;

import com.bensonbasement.snorflux.memory.WorldElementInfo;
import com.bensonbasement.snorflux.messages.fromserver.reports.Report;

public abstract class Brain implements Serializable {

	private BrainTeam team;
	private List<Actor> controlledActors;
	
	public Brain(BrainTeam team) {
		this.controlledActors = new LinkedList<Actor>();
		this.team = team;
		this.team.addBrain(this);
	}
	
	/**
	 * Should ONLY be called from the Actor class.
	 */
	public void addControlledActor(Actor actor) {
		this.controlledActors.add(actor);
		this.team.actorVisibilityUpdated();
	}

	/**
	 * Should ONLY be called from the Actor class.
	 */
	public void removeControlledActor(Actor actor) {
		this.controlledActors.remove(actor);
		this.team.actorVisibilityUpdated();
	}
	
	public BrainTeam getBrainTeam() {
		return this.team;
	}

	/**
	 * Called to notify the brain that an actor's
	 * visibility has changed.
	 * Call ONLY from the Actor class.
	 */
	public void actorVisibilityUpdated() {
		this.team.actorVisibilityUpdated();
	}
	
	public List<Actor> getControlledActors() {
		return this.controlledActors;
	}
	
	public abstract void receiveInfo(WorldElementInfo info);
	public abstract void receiveReport(Report report);
	public abstract void deleteInfo(long worldElementID);
	public abstract void updateVisibility(Set<Long> newlyVisibleSpaceIDs, Set<Long> newlyNonVisibleSpaceIDs);
}
